# 方法1
from datetime import *
riqi = str(input())
dat_1 = datetime(int(riqi[0:4]),int(riqi[4:6]),int(riqi[6:])) # 格式化为日期格式
for i in range(int(riqi),int(riqi)+10000000):
    dat_1 += timedelta(days=1)            # 加一天
    s = "%d%02d%02d"%(dat_1.year,dat_1.month,dat_1.day)   # 规定格式为yyyy mm dd
    if s==s[::-1]: # 判断前后是否相等
        print(s)
        break
# ABAB BA BA
for j in range(int(riqi),int(riqi)+100000000):
    dat_1 += timedelta(days=1)
    s = "%d%02d%02d" % (dat_1.year, dat_1.month, dat_1.day)
    # 判断ababbaba
    if s[0] == s[2] == s[5] == s[7] and s[1] == s[3] == s[4] == s[6]:
        print(s)
        break

# 方法2
from datetime import *
riqi = str(input())
dat_1 = datetime(int(riqi[0:4]),int(riqi[4:6]),int(riqi[6:]))  # 格式化为日期格式
flag=True                                                      # 定义布尔型变量
for i in range(int(riqi),int(riqi)+10000000):
    dat_1 += timedelta(days=1)                                 # 加一天
    s = "%d%02d%02d"%(dat_1.year,dat_1.month,dat_1.day)        # 规定格式为yyyy mm dd
    # 判断为回文
    if s == s[::-1]:
        if flag:
            print(s)
            flag = False
        # 判断ababbaba
        if s[0] == s[2] == s[-1] == s[-3] and s[1] == s[3] == s[-2] == s[-4]:
            print(s)
            break

from datetime import *
import sys
riqi = str(input())
date = datetime(int(riqi[0:4]),int(riqi[4:6]),int(riqi[6:]))
flsh = True
for i in range(int(riqi),900000000):
    date += timedelta(days=1)
    s = "%d%02d%02d"%(date.year,date.month,date.day)
    if s ==s[::-1]:
        if flsh:
            print(s)
            flsh = False
        if s[0]==s[2]==s[5]==s[7]and s[1]==s[3]==s[4]==s[6]:
            print(s)
            sys.exit()


